// @ts-nocheck
/* chrome-api-stub.extension.ts */
const eventsStub = {
  addListener() {},
  removeListener() {},
};

interface Sender {
  tab: {
    id: string;
  };
}

interface Port {
  name: string;
  postMessage: (message: unknown) => void;
  onMessage: {
    addListener: (listener: (message: unknown) => void) => void;
    removeListener: (listener: (message: unknown) => void) => void;
  };
  onDisconnect: {
    addListener: (listener: () => void) => void;
    removeListener: (listener: () => void) => void;
  };
  sender: Sender;
}

type ConnectListener = (port: Port) => void;
const connectListeners: ConnectListener[] = [];
const onConnect = {
  addListener(listener: ConnectListener) {
    connectListeners.push(listener);
  },
  removeListener(listener: ConnectListener) {
    const idx = connectListeners.indexOf(listener);
    if (idx === -1) {
      return;
    }
    connectListeners.splice(idx, 1);
  },
};
export function addConnection(port: Port) {
  connectListeners.slice().forEach((listener) => listener(port));
}

type MessageListener = (request: unknown, sender: Sender) => void;
const messageListeners: MessageListener[] = [];
const onMessage = {
  addListener(listener: MessageListener) {
    messageListeners.push(listener);
  },
  removeListener(listener: MessageListener) {
    const idx = messageListeners.indexOf(listener);
    if (idx === -1) {
      return;
    }
    messageListeners.splice(idx, 1);
  },
};
export function postMessage(request: unknown, sender: Sender) {
  messageListeners.slice().forEach((listener) => listener(request, sender));
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const chrome = {
  action: {
    enable() {},
    disable() {},
    setIcon() {},
  },
  commands: {
    onCommand: eventsStub,
    getAll(cb: unknown) {},
  },
  contextMenus: {
    create() {},
    removeAll() {},
    onClicked: eventsStub,
  },
  notifications: {
    clear() {},
    create() {},
    onClicked: eventsStub,
  },
  runtime: {
    onInstalled: eventsStub,
    openOptionsPage() {},
    onConnect,
    onMessage,
    onConnectExternal: eventsStub,
    onMessageExternal: eventsStub,
    id: "chrome-stub-runtime",
  },
  storage: {
    onChanged: eventsStub,
    local: {
      set() {},
      get(defaults: unknown, cb: (data: unknown) => void) {
        cb(defaults);
      },
    },
  },
  windows: {
    create() {},
    update() {},
  },
};

const navigator = {
  userAgent: "ReactNative",
};

/* background.bundle.js */
"use strict";(()=>{var je=Object.create;var fe=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ge=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Fe(t))!Ue.call(e,r)&&r!==n&&fe(e,r,{get:()=>t[r],enumerable:!(o=$e(t,r))||o.enumerable});return e};var pe=(e,t,n)=>(n=e!=null?je(Be(e)):{},Ge(t||!e||!e.__esModule?fe(n,"default",{value:e,enumerable:!0}):n,e));var Q=R((St,Ee)=>{Ee.exports=He;function He(e,t){if(t!=="$")for(var n=ze(t),o=0;o<n.length;o++)t=n[o].toString().replace(/\\"/g,'"'),!(typeof e[t]>"u"&&o!==n.length-1)&&(e=e[t]);return e}function ze(e){for(var t=/(?:\.(\w+))|(?:\[(\d+)\])|(?:\["((?:[^\\"]|\\.)*)"\])/g,n=[],o;o=t.exec(e);)n.push(o[1]||o[2]||o[3]);return n}});var he=R(V=>{var Xe=Q(),Ie=Z();V.getRegexFlags=function(t){var n="";return t.ignoreCase&&(n+="i"),t.global&&(n+="g"),t.multiline&&(n+="m"),n};V.stringifyFunction=function(t,n){if(typeof n=="function")return n(t);var o=t.toString(),r=o.match(/^[^{]*{|^[^=]*=>/),s=r?r[0]:"<function> ",i=o[o.length-1]==="}"?"}":"";return s.replace(/\r\n|\n/g," ").replace(/\s+/g," ")+" /* ... */ "+i};V.restore=function(t,n){var o=t[0],r=t.slice(1);switch(o){case"$":return Xe(n,t);case"r":var s=r.indexOf(","),i=r.slice(0,s),a=r.slice(s+1);return RegExp(a,i);case"d":return new Date(+r);case"f":var d=function(){throw new Error("can't run jsan parsed function")};return d.toString=function(){return r},d;case"u":return;case"e":var u=new Error(r);return u.stack="Stack is unavailable for jsan parsed errors",u;case"s":return Symbol(r);case"g":return Symbol.for(r);case"m":return new Map(Ie.parse(r));case"l":return new Set(Ie.parse(r));case"n":return NaN;case"i":return 1/0;case"y":return-1/0;default:return console.warn("unknown type",t),t}}});var Oe=R(q=>{var Tt=Q(),D=he(),Qe=typeof WeakMap<"u"?WeakMap:function(){var e=[],t=[];return{set:function(n,o){e.push(n),t.push(o)},get:function(n){for(var o=0;o<e.length;o++)if(e[o]===n)return t[o]}}};q.decycle=function e(t,n,o,r){"use strict";r=r||new Qe;var s=!Object.prototype.hasOwnProperty.call(n,"circular"),i=n.refs!==!1;return(function a(d,u,m){var p,f,A,c=typeof o=="function"?o(m||"",d):d;if(n.date&&c instanceof Date)return{$jsan:"d"+c.getTime()};if(n.regex&&c instanceof RegExp)return{$jsan:"r"+D.getRegexFlags(c)+","+c.source};if(n.function&&typeof c=="function")return{$jsan:"f"+D.stringifyFunction(c,n.function)};if(n.nan&&typeof c=="number"&&isNaN(c))return{$jsan:"n"};if(n.infinity){if(Number.POSITIVE_INFINITY===c)return{$jsan:"i"};if(Number.NEGATIVE_INFINITY===c)return{$jsan:"y"}}if(n.undefined&&c===void 0)return{$jsan:"u"};if(n.error&&c instanceof Error)return{$jsan:"e"+c.message};if(n.symbol&&typeof c=="symbol"){var T=Symbol.keyFor(c);return T!==void 0?{$jsan:"g"+T}:{$jsan:"s"+c.toString().slice(7,-1)}}if(n.map&&typeof Map=="function"&&c instanceof Map&&typeof Array.from=="function")return{$jsan:"m"+JSON.stringify(e(Array.from(c),n,o,r))};if(n.set&&typeof Set=="function"&&c instanceof Set&&typeof Array.from=="function")return{$jsan:"l"+JSON.stringify(e(Array.from(c),n,o,r))};if(c&&typeof c.toJSON=="function")try{c=c.toJSON(m)}catch{var y=m||"$";return"toJSON failed for '"+(r.get(c)||y)+"'"}if(typeof c=="object"&&c!==null&&!(c instanceof Boolean)&&!(c instanceof Date)&&!(c instanceof Number)&&!(c instanceof RegExp)&&!(c instanceof String)&&typeof c!="symbol"&&!(c instanceof Error)){if(typeof c=="object"){var g=r.get(c);if(g){if(s&&i)return{$jsan:g};var E=u.split(".").slice(0,-1).join(".");if(E.indexOf(g)===0)return s?{$jsan:g}:typeof n.circular=="function"?n.circular(c,u,g):n.circular;if(i)return{$jsan:g}}r.set(c,u)}if(Object.prototype.toString.apply(c)==="[object Array]")for(A=[],p=0;p<c.length;p+=1)A[p]=a(c[p],u+"["+p+"]",p);else{A={};for(f in c)if(Object.prototype.hasOwnProperty.call(c,f)){var O=/^\w+$/.test(f)?"."+f:"["+JSON.stringify(f)+"]";A[f]=f==="$jsan"?[a(c[f],u+O)]:a(c[f],u+O,f)}}return A}return c})(t,"$")};q.retrocycle=function(t){"use strict";return(function n(o){var r,s,i,a;if(o&&typeof o=="object")if(Object.prototype.toString.apply(o)==="[object Array]")for(r=0;r<o.length;r+=1)s=o[r],s&&typeof s=="object"&&(s.$jsan?o[r]=D.restore(s.$jsan,t):n(s));else for(i in o){if(typeof o[i]=="string"&&i==="$jsan")return D.restore(o.$jsan,t);i==="$jsan"&&(o[i]=o[i][0]),typeof o[i]=="object"&&(s=o[i],s&&typeof s=="object"&&(s.$jsan?o[i]=D.restore(s.$jsan,t):n(s)))}return o})(t)}});var Z=R(ee=>{var xe=Oe();ee.stringify=function(t,n,o,r){if(arguments.length<4)try{return arguments.length===1?JSON.stringify(t):JSON.stringify.apply(JSON,arguments)}catch{}var s=r||!1;typeof s=="boolean"&&(s={date:s,function:s,regex:s,undefined:s,error:s,symbol:s,map:s,set:s,nan:s,infinity:s});var i=xe.decycle(t,s,n);return arguments.length===1?JSON.stringify(i):JSON.stringify(i,Array.isArray(n)?n:null,o)};ee.parse=function(t,n){var o=/"\$jsan"/.test(t),r;return arguments.length===1?r=JSON.parse(t):r=JSON.parse(t,n),o&&(r=xe.retrocycle(r)),r}});var te=R((ht,be)=>{be.exports=Z()});var $=navigator.userAgent.includes("Electron"),le=navigator.userAgent.includes("Firefox");($&&location.pathname==="/background.bundle.js"||le)&&(chrome.runtime.onConnectExternal={addListener(){}},chrome.runtime.onMessageExternal={addListener(){}},$?(chrome.notifications={onClicked:{addListener(){}},create(){},clear(){}},chrome.contextMenus={onClicked:{addListener(){}}},chrome.commands={onCommand:{addListener(){}}}):(chrome.storage.sync=chrome.storage.local,chrome.runtime.onInstalled={addListener:e=>e()}));if($){(!chrome.storage.local||!chrome.storage.local.remove)&&(chrome.storage.local={set(t,n){for(let[o,r]of Object.entries(t))localStorage.setItem(o,r);n&&n()},get(t,n){let o=Object.fromEntries(Object.entries(t).map(([r,s])=>[r,localStorage.getItem(r)??s]));n&&n(o)},remove(t,n){if(Array.isArray(t))for(let o of t)localStorage.removeItem(o);else localStorage.removeItem(t);n&&n()}});let e=chrome.runtime.sendMessage;chrome.runtime.sendMessage=function(...t){return typeof t[arguments.length-1]=="function"&&Array.prototype.pop.call(t),e(...t)}}(le||$)&&(chrome.storage.sync=chrome.storage.local);function S(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var Ve=typeof Symbol=="function"&&Symbol.observable||"@@observable",ye=Ve,z=()=>Math.random().toString(36).substring(7).split("").join("."),We={INIT:`@@redux/INIT${z()}`,REPLACE:`@@redux/REPLACE${z()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${z()}`},F=We;function Ke(e){if(typeof e!="object"||e===null)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function X(e,t,n){if(typeof e!="function")throw new Error(S(2));if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(S(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(S(1));return n(X)(e,t)}let o=e,r=t,s=new Map,i=s,a=0,d=!1;function u(){i===s&&(i=new Map,s.forEach((y,g)=>{i.set(g,y)}))}function m(){if(d)throw new Error(S(3));return r}function p(y){if(typeof y!="function")throw new Error(S(4));if(d)throw new Error(S(5));let g=!0;u();let E=a++;return i.set(E,y),function(){if(g){if(d)throw new Error(S(6));g=!1,u(),i.delete(E),s=null}}}function f(y){if(!Ke(y))throw new Error(S(7));if(typeof y.type>"u")throw new Error(S(8));if(typeof y.type!="string")throw new Error(S(17));if(d)throw new Error(S(9));try{d=!0,r=o(r,y)}finally{d=!1}return(s=i).forEach(E=>{E()}),y}function A(y){if(typeof y!="function")throw new Error(S(10));o=y,f({type:F.REPLACE})}function c(){let y=p;return{subscribe(g){if(typeof g!="object"||g===null)throw new Error(S(11));function E(){let b=g;b.next&&b.next(m())}return E(),{unsubscribe:y(E)}},[ye](){return this}}}return f({type:F.INIT}),{dispatch:f,subscribe:p,getState:m,replaceReducer:A,[ye]:c}}function Je(e){Object.keys(e).forEach(t=>{let n=e[t];if(typeof n(void 0,{type:F.INIT})>"u")throw new Error(S(12));if(typeof n(void 0,{type:F.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(S(13))})}function ge(e){let t=Object.keys(e),n={};for(let i=0;i<t.length;i++){let a=t[i];typeof e[a]=="function"&&(n[a]=e[a])}let o=Object.keys(n),r,s;try{Je(n)}catch(i){s=i}return function(a={},d){if(s)throw s;let u=!1,m={};for(let p=0;p<o.length;p++){let f=o[p],A=n[f],c=a[f],T=A(c,d);if(typeof T>"u"){let y=d&&d.type;throw new Error(S(14))}m[f]=T,u=u||T!==c}return u=u||o.length!==Object.keys(a).length,u?m:a}}function Ye(...e){return e.length===0?t=>t:e.length===1?e[0]:e.reduce((t,n)=>(...o)=>t(n(...o)))}function me(...e){return t=>(n,o)=>{let r=t(n,o),s=()=>{throw new Error(S(15))},i={getState:r.getState,dispatch:(d,...u)=>s(d,...u)},a=e.map(d=>d(i));return s=Ye(...a)(r.dispatch),{...r,dispatch:s}}}var w="devTools/UPDATE_STATE",B="devTools/SET_STATE",Se="devTools/SELECT_INSTANCE",L="devTools/REMOVE_INSTANCE",Ae="devTools/CLEAR_INSTANCES",C="devTools/LIFTED_ACTION";var Te="devTools/TOGGLE_SYNC",U="devTools/TOGGLE_PERSIST",G="devTools/SET_PERSIST";var v=Symbol.for("__serializedType__"),k=Symbol.for("__serializedRef__");var ne=pe(te());function Ze(e,t){if(typeof t=="object"&&t!==null&&"__serializedType__"in t&&typeof t.data=="object"){let n=t.data;return n[v]=t.__serializedType__,"__serializedRef__"in t&&(n[k]=t.__serializedRef__),n}return t}function N(e,t){if(typeof e!="string")return e;try{return t?ne.default.parse(e,Ze):ne.default.parse(e)}catch{return}}function W(e,t=1){let n=t,o=e.stagedActionIds.slice(1,n+1);for(let r=0;r<o.length;r++)if(e.computedStates[r+1].error){n=r,o=e.stagedActionIds.slice(1,n+1);break}else delete e.actionsById[o[r]];e.skippedActionIds=e.skippedActionIds.filter(r=>!o.includes(r)),e.stagedActionIds=[0,...e.stagedActionIds.slice(n+1)],e.committedState=e.computedStates[n].state,e.computedStates=e.computedStates.slice(n),e.currentStateIndex=e.currentStateIndex>n?e.currentStateIndex-n:0}function K(e,t,n,o=1,r,s){let i=o-1,a={...e};if(a.currentStateIndex===a.stagedActionIds.length-1&&a.currentStateIndex++,a.stagedActionIds=[...a.stagedActionIds,i],a.actionsById={...a.actionsById},n.type==="PERFORM_ACTION"?a.actionsById[i]=n:a.actionsById[i]={action:n.action||n,timestamp:n.timestamp||Date.now(),stack:n.stack,type:"PERFORM_ACTION"},a.nextActionId=o,a.computedStates=[...a.computedStates,{state:t}],s)W(a);else if(r){let d=a.stagedActionIds.length-r;d>0&&W(a,d)}return a}var Ne={selected:null,current:"default",sync:!1,connections:{},options:{default:{features:{}}},states:{default:{actionsById:{},computedStates:[],currentStateIndex:-1,nextActionId:0,skippedActionIds:[],stagedActionIds:[]}}};function qe(e,t,n,o){let r=t.payload,s=t.actionsById;s?(r={...r,actionsById:N(s,o),computedStates:N(t.computedStates,o)},t.type==="STATE"&&t.committedState&&(r.committedState=r.computedStates[0].state)):r=N(r,o);let i,a=e[n]||e.default,d=t.action&&N(t.action,o)||{};switch(t.type){case"INIT":i=K(e.default,r,{action:{type:"@@INIT"},timestamp:d.timestamp||Date.now()});break;case"ACTION":{let u=t.isExcess,m=t.nextActionId||a.nextActionId+1,p=t.maxAge;if(Array.isArray(d)){i=a;for(let f=0;f<d.length;f++)i=K(i,t.batched?r:r[f],d[f],i.nextActionId+1,p,u)}else i=K(a,r,d,m,p,u);break}case"STATE":i=r,i.computedStates.length<=i.currentStateIndex&&(i.currentStateIndex=i.computedStates.length-1);break;case"PARTIAL_STATE":{let u=t.maxAge,m=r.nextActionId,p=r.stagedActionIds,f=r.computedStates,A,c,T;if(m>u){let E=a.stagedActionIds,O=E.indexOf(p[1]),b;if(O>0){c=a.computedStates.slice(O-1),A={...a.actionsById};for(let H=1;H<O;H++)b=E[H],b&&delete A[b];T=f[0].state}else A=a.actionsById,c=a.computedStates,T=a.committedState}else A=a.actionsById,c=a.computedStates,T=a.committedState;f=[...c,...f];let y=f.length,g=r.currentStateIndex;y<=g&&(g=y-1),i={...a,actionsById:{...A,...r.actionsById},computedStates:f,currentStateIndex:g,nextActionId:m,stagedActionIds:p,committedState:T};break}case"LIFTED":i=a;break;default:return e}return t.liftedState&&(i={...i,...t.liftedState}),{...e,[n]:i}}function et(e,{action:t}){if(t.type==="JUMP_TO_STATE"||t.type==="JUMP_TO_ACTION"){let n=e.selected||e.current,o=e.states[n],r=t.type==="JUMP_TO_STATE"?t.index:o.stagedActionIds.indexOf(t.actionId);return{...e,states:{...e.states,[n]:{...o,currentStateIndex:r}}}}return e}function tt(e,t){let n=e.connections[t];if(!n)return e;let o={...e.connections},r={...e.options},s={...e.states},i=e.selected,a=e.current,d=e.sync;return delete o[t],n.forEach(u=>{if(u===i&&(i=null,d=!1),u===a){let m=Object.keys(o)[0];m?a=o[m][0]:a="default"}delete r[u],delete s[u]}),{selected:i,current:a,sync:d,connections:o,options:r,states:s}}function nt({type:e,action:t,name:n,libConfig:o={}},r,s){let i,a,d=o.actionCreators||t;return typeof d=="string"&&(d=JSON.parse(d)),Array.isArray(d)&&(a=d),e==="STATE"&&(i="redux"),{name:o.name||n||s,connectionId:r,explicitLib:o.type,lib:i,actionCreators:a,features:o.features?o.features:{lock:i==="redux",export:o.type==="redux"?"custom":!0,import:"custom",persist:!0,pause:!0,reorder:!0,jump:!0,skip:!0,dispatch:!0,sync:!0,test:!0},serialize:o.serialize}}function _e(e=Ne,t){switch(t.type){case w:{let{request:n}=t;if(!n)return e;let o=t.id||n.id,r=n.instanceId||o,s=e.connections,i=e.options;return typeof e.options[r]>"u"&&(s={...e.connections,[o]:[...s[o]||[],r]},i={...i,[r]:nt(n,o,r)}),{...e,current:r,connections:s,options:i,states:qe(e.states,n,r,i[r].serialize)}}case B:return{...e,states:{...e.states,[ot(e)]:t.newState}};case U:return{...e,persisted:!e.persisted};case G:return{...e,persisted:t.payload};case Te:return{...e,sync:!e.sync};case Se:return{...e,selected:t.selected,sync:!1};case L:return tt(e,t.id);case C:{if(t.message==="DISPATCH")return et(e,t);if(t.message==="IMPORT"){let n=e.selected||e.current;if(e.options[n].features.import===!0)return{...e,states:{...e.states,[n]:N(t.state)}}}return e}case Ae:return Ne;default:return e}}var ot=e=>e.selected||e.current;var oe=pe(te());function rt(e,t){if(typeof t=="object"&&t!==null&&v in t){let n=t[v],o={...t};delete o[v];let r={data:o,__serializedType__:n};return k in t&&(r.__serializedRef__=o[k]),r}return t}function h(e,t){return t?oe.default.stringify(e,rt,null,!0):oe.default.stringify(e)}function st(e){let t=new Set(e.skippedActionIds);return{...e,actionsById:Object.fromEntries(Object.entries(e.actionsById).filter(([n])=>!t.has(parseInt(n,10)))),stagedActionIds:e.stagedActionIds.filter(n=>!t.has(n)),skippedActionIds:[],currentStateIndex:Math.min(e.currentStateIndex,e.stagedActionIds.length-1)}}function P(e,t,n,o,r,s){let i=s||e.getState().instances,a=i.states[n],d=i.options[n];if(t!=="DISPATCH")return t==="IMPORT"?d.features.import===!0?h(a.computedStates[a.currentStateIndex].state,!0):r:void 0;if(d.lib!=="redux")switch(o.type){case"TOGGLE_ACTION":return h(a,!0);case"JUMP_TO_STATE":return h(a.computedStates[o.index].state,!0);case"JUMP_TO_ACTION":return h(a.computedStates[a.stagedActionIds.indexOf(o.actionId)].state,!0);case"ROLLBACK":return h(a.computedStates[0].state,!0);case"SWEEP":e.dispatch({type:B,newState:st(a)});return;default:return}}var it=ge({instances:_e}),we=it;var re={};function x(e){re[e]?chrome.windows.update(re[e],{focused:!0},()=>{chrome.runtime.lastError&&Ce(e)}):Ce(e)}function Ce(e){let t=chrome.runtime.getURL(at(e));chrome.windows.create({type:"popup",url:t},n=>{re[e]=n.id,navigator.userAgent.includes("Firefox")&&chrome.windows.update(n.id,{focused:!0})})}function at(e){switch(e){case"devtools-window":return"devpanel.html";case"devtools-remote":return"remote.html";default:throw new Error("Unrecognized position")}}function ve(e,t,n){chrome.storage.local.get(["s:hostname","s:port","s:secure"],o=>{if(!o["s:hostname"]||!o["s:port"])return;let r=`${o["s:secure"]?"https":"http"}://${o["s:hostname"]}:${o["s:port"]}`;fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({op:"get",id:e})}).then(s=>s.json()).then(s=>{let{payload:i,preloadedState:a}=s;i&&l.dispatch({type:C,message:"IMPORT",state:JSON.stringify({payload:i,preloadedState:a}),id:t,instanceId:`${t}/${n}`})}).catch(function(s){console.warn(s)})})}var ct="socket/CONNECTED",dt="socket/DISCONNECTED",I={tab:{},panel:{}},j={},J=0,ie=(e,t)=>e.tab?e.tab.id:t||e.id,se=32*1024*1024;function M(e){console.log(`Message to monitors: ${e.type}`);for(let t of Object.values(I.panel))try{t.postMessage(e)}catch(n){if(e.type!==w||n==null||n.message!=="Message length exceeded maximum allowed length.")throw n;let o={split:"start"},r=[],s=0;for(let[i,a]of Object.entries(e.request)){if(typeof a=="string"&&(s+=a.length,s>se)){r.push([i,a]);continue}o[i]=a}t.postMessage({...e,request:o});for(let i=0;i<r.length;i++)for(let a=0;a<r[i][1].length;a+=se)t.postMessage({...e,request:{split:"chunk",chunk:[r[i][0],r[i][1].substring(a,a+se)]}});t.postMessage({...e,request:{split:"end"}})}}function Me(e){if(console.log(`Message to tab ${e.id}: ${e.message}`),e.message==="DISPATCH"){let{message:t,action:n,id:o,instanceId:r,state:s}=e;I.tab[o].postMessage({type:t,action:n,state:P(l,t,r,n,s),id:r.toString().replace(/^[^/]+\//,"")})}else if(e.message==="IMPORT"){let{message:t,action:n,id:o,instanceId:r,state:s}=e;I.tab[o].postMessage({type:t,action:n,state:P(l,t,r,n,s),id:r.toString().replace(/^[^/]+\//,"")})}else if(e.message==="ACTION"){let{message:t,action:n,id:o,instanceId:r,state:s}=e;I.tab[o].postMessage({type:t,action:n,state:P(l,t,r,n,s),id:r.toString().replace(/^[^/]+\//,"")})}else if(e.message==="EXPORT"){let{message:t,action:n,id:o,instanceId:r,state:s}=e;I.tab[o].postMessage({type:t,action:n,state:P(l,t,r,n,s),id:r.toString().replace(/^[^/]+\//,"")})}else{let{message:t,action:n,id:o,instanceId:r,state:s}=e;I.tab[o].postMessage({type:t,action:n,state:P(l,t,r,n,s),id:r.toString().replace(/^[^/]+\//,"")})}}function ae(e){console.log(`Message to all tabs: ${e.type}`);for(let t of Object.values(I.tab))t.postMessage(e)}function ut(){let e=l.getState().instances,t=e.states[e.current],n=t.computedStates[t.currentStateIndex];return n?n.error:!1}function ft(){let e=l.getState();if(e.instances.persisted)for(let t of Object.keys(e.instances.connections)){if(I.tab[t])return;l.dispatch({type:L,id:t}),M({type:"NA",id:t})}}function ce(e,t){let n=ie(t);if(console.log(`Message from tab ${n}: ${e.type??e.split}`),!n)return;if(t.frameId&&(n=`${n}-${t.frameId}`),e.type==="STOP"){Object.keys(l.getState().instances.connections).length||l.dispatch({type:dt});return}if(e.type==="OPEN_OPTIONS"){chrome.runtime.openOptionsPage();return}if(e.type==="OPTIONS"){ae({type:"OPTIONS",options:e.options});return}if(e.type==="GET_REPORT"){ve(e.payload,n,e.instanceId);return}if(e.type==="OPEN"){let s="devtools-window";["remote","window"].includes(e.position)&&(s="devtools-"+e.position),x(s);return}if(e.type==="ERROR"){if(e.payload){M(e);return}if(!e.message)return;let s=ut();chrome.notifications.create("app-error",{type:"basic",title:s?"An error occurred in the reducer":"An error occurred in the app",message:s||e.message,iconUrl:"img/logo/48x48.png",isClickable:!!s});return}let o={type:w,request:e,id:n},r=`${n}/${e.instanceId}`;if("split"in e){if(e.split==="start"){j[r]=e;return}if(e.split==="chunk"){j[r][e.chunk[0]]=(j[r][e.chunk[0]]||"")+e.chunk[1];return}o.request=j[r],delete j[r]}e.instanceId&&(o.request.instanceId=r),l.dispatch(o),M(o)}function Pe(e,t,n){return function o(){console.log(`Disconnected from ${e} ${t}`);let r=I[e][t];n&&r&&r.onMessage.removeListener(n),r&&r.onDisconnect.removeListener(o),delete I[e][t],e==="tab"?l.getState().instances.persisted||(l.dispatch({type:L,id:t}),M({type:"NA",id:t})):(J--,J===0&&ae({type:"STOP"}))}}function Re(e){let t,n;if(l.dispatch({type:ct,port:e}),e.name==="tab")t=ie(e.sender),console.log(`Connected to tab ${t}`),e.sender.frameId&&(t=`${t}-${e.sender.frameId}`),I.tab[t]=e,n=o=>{if(console.log(`Message from tab ${t}: ${o.name}`),o.name==="INIT_INSTANCE"){typeof t=="number"&&(chrome.action.enable(t),chrome.action.setIcon({tabId:t,path:"img/logo/38x38.png"})),J>0&&e.postMessage({type:"START"});let r=l.getState();if(r.instances.persisted){let s=`${t}/${o.instanceId}`,i=r.instances.states[s];if(!i)return;Me({message:"IMPORT",id:t,instanceId:s,state:h(i,r.instances.options[s].serialize)})}return}o.name==="RELAY"&&ce(o.message,e.sender)},e.onMessage.addListener(n),e.onDisconnect.addListener(Pe("tab",t,n));else if(e.name&&e.name.indexOf("monitor")===0){t=ie(e.sender,e.name),console.log(`Connected to monitor ${t}`),I.panel[t]=e,J++,ae({type:"START"}),n=r=>{console.log(`Message from monitor ${t}: ${r.type}`),l.dispatch(r)},e.onMessage.addListener(n),e.onDisconnect.addListener(Pe("panel",t,n));let{current:o}=l.getState().instances;if(o!=="default"){let r=Object.entries(l.getState().instances.connections).find(([,p])=>p.includes(o))?.[0],s=l.getState().instances.options[o],i=l.getState().instances.states[o],{actionsById:a,computedStates:d,committedState:u,...m}=i;M({type:w,request:{type:"STATE",payload:m,source:"@devtools-page",instanceId:typeof o=="number"?o.toString():o,actionsById:h(a,s.serialize),computedStates:h(d,s.serialize),committedState:typeof u<"u"},id:r??o})}}}chrome.runtime.onConnect.addListener(Re);chrome.runtime.onConnectExternal.addListener(Re);chrome.runtime.onMessage.addListener(ce);chrome.runtime.onMessageExternal.addListener(ce);chrome.notifications.onClicked.addListener(e=>{chrome.notifications.clear(e),x("devtools-window")});var pt=e=>t=>n=>{let o=n;return o.type===C?Me(o):o.type===U&&(ft(),M({type:G,payload:!e.getState().instances.persisted})),t(o)},Le=pt;function de(e){return X(we,e,me(Le))}function ue(){let e=[{id:"devtools-window",title:"Open in a window"},{id:"devtools-remote",title:"Open Remote DevTools"}],t={};chrome.commands.getAll(n=>{for(let{name:o,shortcut:r}of n)t[o]=r;for(let{id:o,title:r}of e)chrome.contextMenus.create({id:o,title:r+(t[o]?" ("+t[o]+")":""),contexts:["all"]})})}async function De(){await chrome.contextMenus.removeAll()}chrome.contextMenus.onClicked.addListener(({menuItemId:e})=>{x(e)});var _={DO_NOT_FILTER:"DO_NOT_FILTER",DENYLIST_SPECIFIC:"DENYLIST_SPECIFIC",ALLOWLIST_SPECIFIC:"ALLOWLIST_SPECIFIC"};var Y;var lt=e=>({...e,filter:typeof e.filter=="boolean"?e.filter&&e.whitelist.length>0?_.ALLOWLIST_SPECIFIC:e.filter?_.DENYLIST_SPECIFIC:_.DO_NOT_FILTER:e.filter==="WHITELIST_SPECIFIC"?_.ALLOWLIST_SPECIFIC:e.filter==="BLACKLIST_SPECIFIC"?_.DENYLIST_SPECIFIC:e.filter}),ke=e=>{Y?e(Y):chrome.storage.sync.get({useEditor:0,editor:"",projectPath:"",maxAge:50,filter:_.DO_NOT_FILTER,whitelist:"",blacklist:"",allowlist:"",denylist:"",shouldCatchErrors:!1,inject:!0,urls:`^https?://localhost|0\\.0\\.0\\.0:\\d+
^https?://.+\\.github\\.io`,showContextMenus:!0},function(t){Y=lt(t),e(Y)})};var l=de();chrome.commands.onCommand.addListener(e=>{x(e)});chrome.runtime.onInstalled.addListener(()=>{chrome.action.disable(),ke(e=>{e.showContextMenus&&ue()})});chrome.storage.onChanged.addListener(e=>{e.showContextMenus&&(e.showContextMenus.newValue?ue():De())});setInterval(()=>void chrome.storage.local.set({"last-heartbeat":new Date().getTime()}),2e4);})();
